package com.tangcan.blog.Controller;

import com.alibaba.fastjson.JSON;
import com.tangcan.blog.Entity.BlogContent;
import com.tangcan.blog.Mapper.TestMapper;
import com.tangcan.blog.Utils.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.tangcan.blog.Entity.User;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/test")
@EnableAutoConfiguration
public class TestController {

    @Autowired
    TestMapper testMapper;

//    @Autowired
//    AppConfig appConfig;


    TokenUtils tokenUtils;

    @RequestMapping(value = "/Hello",method = RequestMethod.GET)
    @ResponseBody
    public List<User> test()
    {
        return testMapper.FindAll();
    }

//    @RequestMapping(value = "/token",method = RequestMethod.GET)
//    @ResponseBody
//    public String tokentest()
//    {
//        String username ="zhangsan";
//        String password = "123";
//        String token = tokenUtils.token(username,password,"admin");
//        boolean verify = tokenUtils.verify("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwYXNzd29yZCI6IjEyMyIsImF1dGhvcml0eSI6InVzZXIiLCJleHAiOjE2MzA5Njk4NjQsInVzZXJuYW1lIjoiemhhbmdzYW4ifQ.ZUL05gC4oCpXJnAYzJwAPvDnmSuGxTNrgx1K1pbc3zk");
//        String data = "{" +
//                "token:" +token+",\n"+
//                "verify:"+verify+",\n"+
//                "}";
//        return data;
//    }
    @RequestMapping(value = "/login",method = RequestMethod.GET)
    @ResponseBody
    public String logintest()
    {
        Map ErrMap = new HashMap();
        ErrMap.put("token","error");
        ErrMap.put("msg","用户不存在");
        return JSON.toJSONString(ErrMap);
    }



    @RequestMapping(value = "/getall",method = RequestMethod.GET)
    @ResponseBody
    public List<BlogContent> getall()
    {

        return testMapper.GetAll();
    }

}
